package com.tqz.dt.business.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * <p>账户的仓储
 *
 * @author tianqingzhao
 * @since 2021/7/7 16:06
 */
@Repository
public class AccountInfoDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public int updateAccountBlance(Integer accountId, double blance) {
        String sql = "update account_info set blance=blance-? where account_id=?";
        return jdbcTemplate.update(sql, blance, accountId);
    }

    public int saveAccountInfo(Integer accountId, double blance) {
        String sql = "insert into account_info(account_id,blance) values(?,?)";
        return jdbcTemplate.update(sql, accountId, blance);
    }

    public double qryBlanceByUserId(Integer accountId) {
        String sql = "select blance from account_info where account_id=" + accountId;
        return jdbcTemplate.queryForObject(sql, Double.class);
    }
}
